
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Won-松的趣味分享</title>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="../bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../css/bass.css"/>
	<link rel="stylesheet" type="text/css" href="../css/funstyle.css"/>
</head>
<body>
	<div class="wrap">
		<!--head-->
		<div class="w100">
			<!--head-top-->
			<div class="headtop w960 clearfix">
				<div class="logo fl"><a href="#"><img src="../img/logo.png"></a></div>
		<?php
			include("../function.php");
			$conn = conn();
			$resourse = mysqli_query($conn,"select * from nav");   
			while ($row = mysqli_fetch_assoc($resourse)){
		?>
				<div class="nav fl">
					<ul>
						<li class="fl ml25"><a href="<?php echo $row["addr"]?>"><?php echo $row['option']?></a></li>
					</ul>
				</div>
		<?php
			}
		?>
			</div>
			<div class="clear"></div>
			<!--head-background-->
			<div class="bg">
				<div class="title"><h2>趣味分享</h2></div>
				<ul class="clearfix">
					<li class='fl'><a href="funsharing.php">全部</a></li>
				<?php 
					$resourse = mysqli_query($conn,"select * from cata_log");   
					while ($data = mysqli_fetch_assoc($resourse)){
				?>
					<li class="fl"><a href="list.php?cata_id=<?=$data["id"]?>"><?=$data["class"]?></a></li>
				<?php 
					}

				?>
				</ul>
			</div>
		</div>
		<div class="clear"></div>
		<!--main-->
	<?php
		if(!array_key_exists('page',  $_GET)) {
			$page = 1;        //如果开始时没有page值，这时将$page赋值为1
		}else{
			$page = $_GET['page'];
		}	
		$result = "select count(*) as count from article";//拿出数据库article表格中的总条数
		$count = mysqli_query($conn,$result);
		$count = mysqli_fetch_assoc($count);
		$sum = $count["count"];//将总条数以数字形式拿出
		$pageSize = 10;//设置每页显示的条数
		$totalpage = (int)ceil($sum/$pageSize);//计算出总共多少页   ceil()拿出大于该数的正数
		$offset =( $page - 1)*$pageSize; //计算出从每页第几条开始拿
		$resourse = mysqli_query($conn,"select * from article order by id desc limit $offset,$pageSize"); 
		while ($row = mysqli_fetch_assoc($resourse)){
	?>
		<div class="content w960 clearfix">
			<div class="left fl"><img style="height:220px;" src="<?php echo $row["img"]?>"></div>
			<div class="center fl">
				<a href="content.php?id=<?php echo $row['id']?>"><h2><?php echo $row["title"]?></h2></a>
				<p><?php echo $row["desc"]?></p>
			</div>
			<div class="right fl">
				<div>浏览次数：<?=$row['view']?></div>
				<div class="time"><?php echo date("Y-m-d H:i:s",$row["create_time"])?></div>
			</div>	
		</div>
	<?php
		}
	?>
		
		<nav>
		  <ul class="pagination">
		<?php
			for ($i=0; $i < $totalpage; $i++) {
				$p = $i+1;
		?>
			<li <?php if($p==$page)echo 'class="active"'?> ><a href="?page=<?=$p?>"><?=$p?></a></li>
		<?php
			}
		?>
		  </ul>
		</nav>
		<div class="bottom btn btn-primary"><a href="#">置顶</a></div>
	</div>
	
</body>
</html>